﻿<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        dfDate.SetValue(DateTime.Now.ToString("yyyy/MM/dd"));
    }


    [DirectMethod]
    public void OnCustomerComboTriggerClick()
    {
        X.AddScript("CustomerListStore.reload()");
    }
</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
    <title>添加送货单</title>
    <script type="text/javascript" src="/Scripts/Commen.js"></script>
    <script type="text/javascript" src="/Scripts/INV_SendOrder/INV_AddOrder.js"></script>
</head>
<body>
    <script type="text/javascript" src="/Scripts/ExtTimeOut.js"></script>
    <script type="text/javascript" src="/Scripts/ExtRequiredFieldPluins.js"></script>
    <script type="text/javascript">
        var changeSortDirect = function () {
            if (SortDirect.Value == "desc" || SortDirect.Value == "") {
                SortDirect.Value = "asc";
            }
            else {
                SortDirect.Value = "desc";
            }
        };
    </script>
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <!-- 产品价格类别数据源 -->
    <ext:Store ID="ProductPriceTypeStore" runat="server" AutoLoad="true">
        <Proxy>
            <ext:HttpProxy Url="/SendOrder/getProductPriceType/" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="FID" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="FID" />
                    <ext:RecordField Name="FName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <!-- 客户列表数据源 -->
    <ext:Store ID="CustomerListStore" runat="server" AutoLoad="true">
        <Proxy>
            <ext:HttpProxy Url="/SendOrder/getCustomerList/" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="FId" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="FId" />
                    <ext:RecordField Name="FName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <!-- 产品列表数据源 -->
    <ext:Store ID="ProductListStore" runat="server" AutoLoad="true">
        <Proxy>
            <ext:HttpProxy Url="/SendOrder/getProductList/" />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="ProductId" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="ProductId" />
                    <ext:RecordField Name="ProductName" />
                    <ext:RecordField Name="ProductModelName" />
                    <ext:RecordField Name="ProductPrice" />
                    <ext:RecordField Name="ProductRemark" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="FType" Value="#{cbProductPriceType}.getValue()" Mode="Raw" />
        </BaseParams>
    </ext:Store>
    <!-- 产品数据源 -->
    <ext:Store ID="ProductStore" runat="server">
        <Reader>
            <ext:ArrayReader>
                <Fields>
                    <ext:RecordField Name="ProductID" />
                    <ext:RecordField Name="ProductName" />
                    <ext:RecordField Name="ProductModel" />
                    <ext:RecordField Name="ProductQty" />
                    <ext:RecordField Name="ProductNumber" />
                    <ext:RecordField Name="ProductPrice" />
                    <ext:RecordField Name="ProductAmount" />
                    <ext:RecordField Name="ProductRemark" />
                </Fields>
            </ext:ArrayReader>
        </Reader>
    </ext:Store>
    <!--当前编辑帐号的FId-->
    <ext:Hidden ID="FIdH" IDMode="Explicit" runat="server" Text="" AutoDataBind="true" />
    <ext:Hidden ID="SortDirect" IDMode="Explicit" runat="server" Text="" AutoDataBind="true" />
    <ext:Hidden ID="FSendOrderStatus" IDMode="Explicit" runat="server" Text="" AutoDataBind="true" />
    <!-- 送货单明细列表数据源 -->
    <ext:Store ID="OrderDetailListStore" IDMode="Explicit" runat="server" RemoteSort="false"
        SkipIdForNewRecords="false" UseIdConfirmation="false" SerializationMode="Complex"
        WarningOnDirty="false">
        <Reader>
            <ext:JsonReader IDProperty="FId" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="FId" DefaultValue="" />
                    <ext:RecordField Name="FParentId" />
                    <ext:RecordField Name="FProductId" />
                    <ext:RecordField Name="FProductNumber" />
                    <ext:RecordField Name="FProductName" />
                    <ext:RecordField Name="FProductModelName" />
                    <ext:RecordField Name="FProductInventoryQty" DefaultValue="0" />
                    <ext:RecordField Name="FQty" DefaultValue="0" />
                    <ext:RecordField Name="FNumber" DefaultValue="0" />
                    <ext:RecordField Name="FPrice" DefaultValue="0" />
                    <ext:RecordField Name="FAmount" DefaultValue="0" />
                    <ext:RecordField Name="FRemark" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <SortInfo Field="FProductNumber" Direction="ASC" />
    </ext:Store>
    <ext:Viewport ID="Viewport" runat="server" Layout="BorderLayout">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Region="North" Split="true" Collapsible="true"
                Padding="5" Height="60" Layout="FormLayout" LabelAlign="Right" LabelWidth="100"
                Header="false" Border="false">
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:DisplayField ID="DisplayField1" runat="server" StyleSpec="color:Red;" Text="注意：1.添加产品之前，请先选择单价类型！ 2.确认订单后就会扣减库存！" />
                            <ext:ToolbarFill ID="ToolbarFill2" runat="server" />
                            <ext:Button ID="Button1" runat="server" Text="新增订单" Icon="Add">
                                <Listeners>
                                    <Click Fn="INV_AddOrder.Mgr.createNewSendOrder" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button4" runat="server" Text="保存订单" Icon="Disk">
                                <Listeners>
                                    <Click Fn="INV_AddOrder.Mgr.Save" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button5" runat="server" Text="导出并打印" Icon="Printer">
                                <Listeners>
                                    <Click Fn="INV_AddOrder.Mgr.Print" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button6" runat="server" Text="确认订单" Icon="Accept">
                                <Listeners>
                                    <Click Fn="INV_AddOrder.Mgr.approveSendOrder" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Items>
                    <ext:Container ID="Container1" runat="server" Layout="HBoxLayout" MarginSpec="0 0 0 0">
                        <Items>
                            <ext:ComboBox ID="cbProductPriceType" runat="server" FieldLabel="单价类型" Flex="2" EmptyText="请选择"
                                DisplayField="FName" ValueField="FID" StoreID="ProductPriceTypeStore" SelectedIndex="0" />
                            <ext:ComboBox ID="cbCustomer" runat="server" FieldLabel="客户名称" Flex="2" EmptyText="请选择"
                                DisplayField="FName" ValueField="FId" StoreID="CustomerListStore">
                                <Listeners>
                                    <BeforeRender Handler="this.onTriggerClick = this.onTriggerClick.createSequence(function () {
                                                               Ext.net.DirectMethods.OnCustomerComboTriggerClick();
                                                           });" />
                                </Listeners>
                            </ext:ComboBox>
                            <ext:DateField ID="dfDate" runat="server" FieldLabel="开单日期" Flex="2" EmptyText="" />
                            <ext:TextField ID="tfOrderNumber" runat="server" FieldLabel="单号" Flex="2" ReadOnly="true" />
                        </Items>
                    </ext:Container>
                </Items>
            </ext:Panel>
            <ext:Panel ID="Panel2" runat="server" Region="Center" Layout="AccordionLayout" Split="true">
                <Items>
                    <ext:GridPanel ID="DetailGridPanel" runat="server" StripeRows="true" ClicksToEdit="1"
                        Height="400" AutoExpandColumn="FProductName" StoreID="OrderDetailListStore" Border="false">
                        <TopBar>
                            <ext:Toolbar ID="TopBar" runat="server">
                                <Items>
                                    <ext:DisplayField ID="MsgDF" runat="server" StyleSpec="color:Red;" Text="" />
                                    <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                                    <%--<ext:Button ID="btInsert" runat="server" Text="插入产品" Icon="Add">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.Insert" />
                                        </Listeners>
                                    </ext:Button>--%>
                                    <ext:Button ID="btAdd" runat="server" Text="添加产品" Icon="Add">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.Add" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btDelete" runat="server" Text="删除产品" Icon="Delete">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.Delete" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btClear" runat="server" Text="清空所有产品" Icon="Cancel">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.Clear" />
                                        </Listeners>
                                    </ext:Button>
                                    <%--<ext:Button ID="btSave" runat="server" Text="保存" Icon="Disk">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.Save" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btPrint" runat="server" Text="导出并打印" Icon="Printer">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.Print" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="Button9" runat="server" Text="确认订单" Icon="Accept">
                                        <Listeners>
                                            <Click Fn="INV_AddOrder.Mgr.approveSendOrder" />
                                        </Listeners>
                                    </ext:Button>--%>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <ColumnModel ID="ColumnModel1" runat="server" DefaultSortable="false">
                            <Columns>
                                <ext:Column ColumnID="FProductNumber" Header="产品编号" DataIndex="FProductNumber" Width="120" Sortable="true">
                                    <Editor>
                                        <ext:TextField runat="server" />
                                        <%--<ext:ComboBox ID="cbProductId" runat="server" DisplayField="ProductId" ValueField="ProductId"
                                            StoreID="ProductListStore" />--%>
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FProductName" Header="产品名称" DataIndex="FProductName" Editable="false">
                                    <Editor>
                                        <ext:TextField runat="server" />
                                        <%--<ext:ComboBox ID="cbProductName" runat="server" DisplayField="ProductName" ValueField="ProductName"
                                            StoreID="ProductListStore" />--%>
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FProductModelName" Header="规格" DataIndex="FProductModelName"
                                    Editable="false" Width="100">
                                    <Editor>
                                        <ext:TextField runat="server" />
                                        <%--<ext:ComboBox ID="cbProductModelName" runat="server" DisplayField="ProductModelName" ValueField="ProductModelName"
                                            StoreID="ProductListStore" />--%>
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FQty" Header="件数" DataIndex="FQty" Width="100">
                                    <Editor>
                                        <ext:NumberField runat="server" AllowBlank="false" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FNumber" Header="数量" DataIndex="FNumber" Width="100">
                                    <Editor>
                                        <ext:NumberField runat="server"  Disabled="false" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FProductInventoryQty" Header="库存件数" DataIndex="FProductInventoryQty"
                                    Width="100" Editable="false">
                                    <Editor>
                                        <ext:NumberField runat="server" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FPrice" Header="单价" DataIndex="FPrice" Width="100" XType="numbercolumn">
                                    <Editor>
                                        <ext:NumberField runat="server" AllowBlank="false" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FAmount" Header="总额" DataIndex="FAmount" Width="100">
                                    <Editor>
                                        <ext:NumberField runat="server" />
                                    </Editor>
                                </ext:Column>
                                <ext:Column ColumnID="FRemark" Header="备注" DataIndex="FRemark" Width="100">
                                    <Editor>
                                        <ext:TextField runat="server" />
                                    </Editor>
                                </ext:Column>
                                <%--<ext:CommandColumn>
                                    <Commands>
                                        <ext:GridCommand CommandName="Delete" Icon="Cross" Text="删除" />
                                    </Commands>
                                </ext:CommandColumn>--%>
                            </Columns>
                        </ColumnModel>
                        <Listeners>
                            <HeaderClick Handler="if (columnIndex === 0) { changeSortDirect(); }" />
                        </Listeners>
                        <SelectionModel>
                            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                        </SelectionModel>
                        <Listeners>
                            <KeyDown Fn="INV_AddOrder.Mgr.startEditing" />
                            <AfterEdit Fn="INV_AddOrder.Mgr.afterEdit" />
                        </Listeners>
                        <View>
                            <ext:GridView ID="GridView1" runat="server">
                                <GetRowClass Fn="INV_AddOrder.Mgr.getRowClass" />
                            </ext:GridView>
                        </View>
                    </ext:GridPanel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
</body>
</html>
